package tool.softT

import shared.Pojo.DiffAnaSoftT
import tool.Pojo._
import shared.Pojo._
import tool.{Pojo, Tool}
import implicits.Implicits._
import tool.plot._
import tool.plot

import java.io.File
import dao._
import play.api.i18n.Messages
import shared.pojo.mission

/** Created by yz on 7/12/2020
  */
trait DiffAnaSoftBT extends AllSoftBT with DiffAnaSoftT {

  override def getFileInfos(workspaceDir: File, index: Int)(implicit
      matrixFileDataDao: MatrixFileDataDao,
      messages: Messages
  ): List[FileInfoData] = {
    val resultDir = new File(workspaceDir.getParentFile, "result")
    List(
      FileInfoData("AllMet_Test.csv", messages("allMetTest")),
      FileInfoData("Volcano_Plot.pdf", messages("volcanoPlot")),
      FileInfoData("Diff_Met_Test.csv", messages("diffMetTest")),
      FileInfoData("AllMet_Z_Score.csv", messages("allMetZScore")),
      FileInfoData("Z_Score_Plot.pdf", messages("zScorePlot")),
      FileInfoData("Diff_Metabolite.csv", messages("diffMetabolite"))
    ).filter { fileInfoData =>
      new File(resultDir, fileInfoData.fileName).exists()
    }
  }

  override def getCommandData(workspaceDir: File, resultDir: File, index: Int): List[CommandData] = {
    val groupFile = new File(workspaceDir, "group.txt")
    val solutionFile = new File(Tool.dataDir, "color_solution/color_solution_1.txt")
    val command =
      s"""
         |${Tool.rScript} ${Tool.rPath.unixPath}/produce_sample_color.R --g ${groupFile.unixPath}  --solution ${solutionFile.unixPath}
         |${Tool.rScript} ${Tool.rPath.unixPath}/fill_sample_color.R --g ${groupFile.unixPath}  --solution ${solutionFile.unixPath} --pc ${plot.ZScore.plotO.configFileName}
         |${Tool.rScript} ${new File(Tool.rPath, "volcano_calculate.R").unixPath}
         |${Tool.rScript} ${new File(Tool.rPath, "fill_var_names.R").unixPath}
           """.stripMargin
      val plotCommands =List(
        plot.VolcanoPlot.getCommand(workspaceDir, idStr = ""),
        plot.ZScore.getCommand(workspaceDir, idStr = "",convert = false)
      )
    List(CommandData(workspaceDir, List(command):::plotCommands))
  }

  override def producePlotConfigFile(workspaceDir: File, index: Int): Any = {
    plot.VolcanoPlot.initConfigFile(workspaceDir, idStr = "")
    plot.ZScore.initConfigFile(workspaceDir, idStr = "")
  }

}
